#include <iostream>
#include <vector>
#include <string>
#include <sw/redis++/redis++.h>
#include "until.hpp"
#include <thread>
using namespace std;
using namespace chrono_literals;


void test1(sw::redis::Redis& redis)
{
    cout << "test lpush lpop" << endl;
    redis.flushall();

    //1.单个
    redis.lpush("key1","111");

    //2.多个
    redis.lpush("key1",{"222","333","444"});

    //3.容器
    vector<string> vs{"555","666"};
    redis.lpush("key1",vs.begin(),vs.end());

    vector<string> ret;
    back_insert_iterator<vector<string>> bit(ret);
    redis.lrange("key1",0,-1,bit);

    PrintElenums(ret);

    cout << "——————————————————————————" << endl;

    redis.lpop("key1");
}

void test2(sw::redis::Redis& redis)
{
    cout << "test blpop llen" << endl;
    redis.flushall();

    //不设置超时时间，默认永久阻塞
    sw::redis::OptionalStringPair osp = redis.blpop("key1");
    if(osp)
    {
        cout << osp.value().first << endl;
        cout << osp.value().second << endl;
        cout << "————————————————" << endl;
        cout << osp->first << endl;
        cout << osp->second << endl;
    }
    else
        cout << "无效数据" << endl;
}

int main()
{
    sw::redis::Redis redistmp("tcp://127.0.0.1:6379");

    //test1(redistmp);
    test2(redistmp);

    return 0;
}